package com.imm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imm.common.Result;
import com.imm.dto.DishDTO;
import com.imm.pojo.Dish;
import com.imm.service.IDishService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Resource
    private IDishService dishService;

    @GetMapping("/page")
    public Result<Page<DishDTO>> page(int page, int pageSize, String name) {
        return dishService.pageDish(page, pageSize, name);
    }

    @GetMapping("{id}")
    public Result<DishDTO> findOne(@PathVariable(value = "id") Long id) {
        return dishService.findOne(id);
    }

    @PutMapping
    public Result<String> updateOne(@RequestBody DishDTO dishDTO) {
        return dishService.updateOne(dishDTO);
    }

    @PostMapping("/status/{status}")
    public Result<String> changeStatus(@PathVariable("status") Integer status, Long ...ids) {
        return dishService.changeStatus(status, ids);
    }

    @DeleteMapping
    public Result<String> delete(Long ...ids) {
        return dishService.delete(ids);
    }

    @GetMapping("/list")
    public Result<List<DishDTO>> listDish(DishDTO dishDTO) {
        return dishService.listDish(dishDTO);
    }


    @PostMapping
    public Result<String> insert(@RequestBody DishDTO dishDTO) {
        return dishService.insert(dishDTO);
    }


}
